#ifndef __3E657D23_24B1_426e_B8EC_01624FB2F171__
#define __3E657D23_24B1_426e_B8EC_01624FB2F171__

#include "../import/head.h"
#include "../tools/head.h"

/////////////////////////////////////////////////////////////////////////////////////////
// 

namespace xos
{
    class tcp_impl;

    // 
    // socket_impl
    // 
    class socket_impl
    {
    public:
        socket_impl();
        ~socket_impl();

    public:
        void * m_pUserData;
        sockaddr_in m_addr;
        int m_hSocket;

    public:
        int get_ip_by_name( const char * lpszName, unsigned long & dwIP, char * lpszIP );
        int get_ip_by_name( const char * lpszName, char * lpszIP );

        int get_socket_addr( char * lpszIp, unsigned short * lpusPort );
        int get_peer_addr( char * lpszIp, unsigned short * lpusPort );
        int get_ip_port( char * lpszIp, unsigned short * lpusPort );

        int udp_init( const char * lpszLocalIp, unsigned short usLocalPort );
        int udp_send( const char * lpMsg, int nLen, const char * lpszToIp, unsigned short usToPort );
        int udp_recv( char * lpMsg, int nLen, char * lpszFromIp, unsigned short * lpusFromPort );

        int tcp_init( const char * lpszLocalIp, unsigned short usLocalPort );
        int tcp_accept( tcp_impl ** ppv );
        int tcp_connect( const char * lpszServerIp, unsigned short usServerPort );
        int tcp_send( const char * lpMsg, int nLen );
        int tcp_recv( char * lpMsg, int nLen );

        int set_async( bool bAsync );
        int close();

        int init();
        int term();
    };
} // xos

#endif // __3E657D23_24B1_426e_B8EC_01624FB2F171__
